/**
 * Created by evantang on 2018/4/26.
 */
import {BaseAuthenticateComponent} from "../baseAuthenticate.component";
import {Router, ActivatedRoute} from "@angular/router";
import {ElementRef, Component, Input, ViewChild} from "@angular/core";

@Component({
  selector: "app-rich-text",
  templateUrl: "./rich-text.component.html"
})
export class RichTextComponent extends BaseAuthenticateComponent {

  /**
   * 待显示的文本内容
   */
  @Input() contentsText: string;

  /**
   * 富文本显示内容
   */
  @ViewChild('richText') richText: any;

  constructor(protected a_router: Router, public element: ElementRef, public route: ActivatedRoute) {
    super(a_router, element, route);
  }


  ngOnChanges() {
    if (this.contentsText) {
      this.contentsText = this.contentsText.replace(/\n/g, '<br>');
      this.contentsText = this.contentsText.replace(/\s/g, '&nbsp;');
      this.richText.nativeElement.innerHTML = this.contentsText;

      // const regex = new RegExp('\n', 'g');
      // this.rows = !this.contentsText.match(regex) ? 0 : this.contentsText.match(regex).length + 1;
    }

  }



}
